package controler.p3_fitnessapp;

import java.util.ArrayList;
import java.util.List;

import model.p3_fitnessapp.MySQLiteHelper;
import model.p3_fitnessapp.TrainingPlan;
import unteractivities.p3_fitnessapp.UActNewTrainingplan;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

/**
 * 
 * @author 
 * 
 */
public class ActTrainingplan extends Activity {

	/*
	 * ==========================================================================
	 * Globale Variablen
	 * ========================================================
	 */
	
	List<TrainingPlan> tpList = new ArrayList<TrainingPlan>();
	List<String> tpListView = new ArrayList<String>();
	public final static String ID_EXTRA="controller.p3_fitnessapp._ID";

	/*
	 * ==========================================================================
	 * Android Methoden ========================================================
	 */

	/**
	 * @author tiziancockx
	 */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.act_edit_trainingsplan);

	 
		
		ArrayAdapter<String> ap_trainingsplan = new ArrayAdapter<String>(
				ActTrainingplan.this, android.R.layout.simple_list_item_1, tpListView);
			

		ListView tp_ListView = (ListView) findViewById(R.id.listViewTp);
		tp_ListView.setAdapter(ap_trainingsplan);
		tp_ListView.setOnItemClickListener(onListClick);

	}

	//neue Methode
	
	private AdapterView.OnItemClickListener onListClick = new AdapterView.OnItemClickListener() {
		
	public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
			
			
			Intent i = new Intent(ActTrainingplan.this, ActTest.class);
			
			i.putExtra (ID_EXTRA, String.valueOf(id));
			startActivity(i);
			
		}
		
	};
	
	@Override
	protected void onResume() {
		super.onResume();
		MySQLiteHelper db_trainingsplan = new MySQLiteHelper(getApplicationContext());
		tpList = db_trainingsplan.getAllTrainingplans();
		for (TrainingPlan tp : tpList) {
			String tp_data = tp.getName();
			tpListView.add(tp_data);
		
			
		}
	}

	/*
	 * ==========================================================================
	 * Benutzer Interaktion (Buttons ... )
	 * ========================================================
	 */

	/**
	 * @author maxkuhlmay
	 * @param view
	 */
	public void onButtonClick(View view) {
		switch (view.getId()) {
		case R.id.btn_tp_new:
			startActivity(new Intent(this, UActNewTrainingplan.class));
			
		default:
			break;
		}
	}

	/*
	 * ==========================================================================
	 * Eigene Methoden ========================================================
	 */

	/*
	 * ==========================================================================
	 * Debug Methoden ========================================================
	 */

	/*
	 * ==========================================================================
	 * Getter und Setter
	 * ========================================================
	 */

	
	
}
